package com.liunian.algorithmstudy.tree;

public class MergeTrees617 extends TreeNode {

	public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {
		if (root1 == null && root2 == null) {
			return null;
		} else if (root1 == null) {
			return root2;
		} else if (root2 == null) {
			return root1;
		}
		TreeNode leftTree = mergeTrees(root1.left, root2.left);
		TreeNode rightTree = mergeTrees(root1.right, root2.right);
		return new TreeNode(root1.val + root2.val, leftTree, rightTree);
	}

}
